package cn.hesion.dataStructures.HashTable;

public class EmpLinkedList {
    private Emp head;

    public void add(Emp emp) {
        //判断头指针是否为空
        if (head == null) {
            head = emp;
            return;
        }
        //辅助指针，用于找到链表尾部
        Emp curEmp = head;
        while (true) {
            if (curEmp.next == null) {
                break;
            }
            curEmp = curEmp.next;
        }
        //此时说明找到了链尾，插入雇员信息
        curEmp.next = emp;
    }

    public void list(int no) {
        if (head == null) {
            System.out.println("第 " + (no + 1) + " 链表为空");
            return;
        }
        System.out.print("第 " + (no + 1) + " 链表的信息为");
        Emp curEmp = head;
        while (true) {
            System.out.printf("=>id=%d name=%s ", curEmp.id, curEmp.name);
            if (curEmp.next == null) {
                break;
            }
            curEmp = curEmp.next;
        }
        System.out.println();
    }
    public Emp  findEmpById(int id){
        //判断链表是否为空
        if(head == null) {
            System.out.println("链表为空");
            return null;
        }

        Emp curEmp = head;
        while (true){
            if(curEmp.id==id){
                System.out.println("没有该雇员");
                break;
            }
            //这里表面没有该雇员
            if(curEmp.next==null){
                curEmp=null;
                break;
            }
            curEmp=curEmp.next;
        }
        return curEmp;
    }
}
